/**
 * 根据日期过滤战绩
 * @param year    年
 * @param month   月
 * @param day     日
 * @param dataArr 需要过滤的战绩数据 ps:里面需要包含create_time字段
 * @returns {Array}
 */
var filterDateRecord = function (year, month, day, dataArr) {
    if (dataArr == undefined) return [];

    var selectDate = year + '-' + month + '-' + day;
    var filterDate = [];
    for (var i = 0; i < dataArr.length; i++) {
        var str = timestamp2time(dataArr[i].create_time);
        if (str.indexOf(selectDate) >= 0) {
            filterDate.push(dataArr[i]);
        }
    }
    return filterDate;
};

/**
 * 根据大赢家过滤战绩
 * @param dataArr
 * @param uid   大赢家uid
 * @returns {Array}
 */
var filterMyMaxSocre = function (dataArr, uid) {
    var filterDate = [];
    for (var i = 0; i < dataArr.length; i++) {
        var data = dataArr[i];
        if (data['winner'] && data['winner'] == uid) {
            var resultscore = data['resultscore'];
            var resultscoreIs0 = true;
            for (var j = 0; j < resultscore.length; j++) {
                if (resultscore[j] > 0) {
                    resultscoreIs0 = false;
                }
            }
            if (!resultscoreIs0) {
                filterDate.push(data);
            }
        }
    }
    return filterDate;
};

/**
 * 根据玩法名称过滤
 * @param wanfaNames
 * @param dataArr
 * @returns {Array}
 */
var filterWanFaName = function (wanfaNames, dataArr) {
    var filterDate = [];
    //如果wanfaNames不存在 或者长度为0  则直接返回原数据
    if (wanfaNames == undefined || wanfaNames.length == 0) {
        return dataArr;
    }
    for (var i = 0; i < dataArr.length; i++) {
        var wanfaInfo = dataArr[i];
        var fieldStr = 'wanfa';
        //获取存储玩法名称的字段
        //目前只有字牌特殊 会把玩法名称存放在optionstring里
        if (wanfaInfo['optionstring'] != undefined) {
            fieldStr = 'optionstring';
        }
        var ops = wanfaInfo[fieldStr];
        for (var j = 0; j < wanfaNames.length; j++) {
            if (ops.indexOf(wanfaNames[j]) >= 0) {
                filterDate.push(wanfaInfo);
                break;
            }
        }
    }
    return filterDate;
};


/**
 * 根据玩法名称过滤
 * @param mapIds
 * @param dataArr
 * @returns {Array}
 */
var filterMapId = function (mapIds, dataArr) {
    var filterDate = [];
    //如果wanfaNames不存在 或者长度为0  则直接返回原数据
    if (mapIds == undefined || mapIds.length == 0) {
        return dataArr;
    }
    for (var i = 0; i < dataArr.length; i++) {
        var wanfaInfo = dataArr[i];
        var mapId = wanfaInfo['map_id'];
        if (mapIds.indexOf(mapId) >= 0) {
            filterDate.push(wanfaInfo);
        }
    }
    return filterDate;
};


/**
 * 根据分数过滤
 * @param score     //最小分数
 * @param dataArr
 * @returns {Array}
 */
var filterMinSocre = function (score, dataArr) {
    var filterDate = [];
    for (var i = 0; i < dataArr.length; i++) {
        var data = dataArr[i];
        if (data['resultscore']) {
            var resultscore = data['resultscore'];
            for (var j = 0; j < resultscore.length; j++) {
                if (resultscore[j] >= score) {
                    filterDate.push(data);
                    break;
                }
            }
        }
    }
    return filterDate;
};

/**
 * 根据玩家UID过滤
 * @param uid
 * @param dataArr
 * @returns {Array}
 */
var filterUId = function (uid, dataArr) {
    var filterDate = [];
    for (var i = 0; i < dataArr.length; i++) {
        var data = dataArr[i];
        for (var j = 1; j <= 9; j++) {
            if (data['uid' + j] == undefined) {
                break;
            }
            var uidStr = data['uid' + j];
            if (uidStr == uid || uidStr.toString().indexOf(uid) >= 0) {
                filterDate.push(data);
                break;
            }
        }
    }
    return filterDate;
};

/**
 * 根据是否标记筛选
 * @param mark
 * @param dataArr
 * @returns {Array}
 */
var filterMark = function (mark, dataArr) {
    var filterDate = [];
    for (var i = 0; i < dataArr.length; i++) {
        var data = dataArr[i];
        //查找所欲未标记的
        if (mark == 0 && (data['mard_record'] == undefined || data['mard_record'] == 0)) {
            filterDate.push(data);
        }
        if (mark == 1 && (data['mard_record'] && data['mard_record'] == 1)) {
            filterDate.push(data);
        }
    }
    return filterDate;
};


/**
 * 过滤所有完成的战绩
 * @param dataArr
 * @returns {Array}
 */
var filterCompleteData = function (dataArr) {
    var filterDate = [];
    for (var i = 0; i < dataArr.length; i++) {
        var data = dataArr[i];
        if (data['resultscore']) {
            var resultscore = data['resultscore'];
            for (var j = 0; j < resultscore.length; j++) {
                if (resultscore[j] > 0) {
                    filterDate.push(data);
                    break;
                }
            }
        }
    }
    return filterDate;
};